package hibernate;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import pojo.Orderstatus;
import pojo.User;
import dao.OrderStatusDAO;

@Repository("OrderStatusDAO")
public class HibernateOrderStatusDAO implements OrderStatusDAO {
	private SessionFactory sessionFactory;
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Transactional
	public Orderstatus getOrderstatus(int orderstatusid) {
		Session session= sessionFactory.getCurrentSession();
        Orderstatus orderstatus = null;
        String hql =String.format("from Orderstatus o where o.orderstatusid ='%s'",orderstatusid);
        Query query = session.createQuery(hql);
       
        List<Orderstatus> listOrderstatus = query.list();
        if(listOrderstatus.size() == 1)
        	orderstatus = listOrderstatus.get(0);
        return orderstatus;
	}

}
